//
//  ZFMapViewControl.swift
//  map
//
//  Created by fyzq on 2024/1/26.
//

import UIKit

class ZFMapViewControl: ZFBaseView {

    var layerLabel:UILabel!
    var kefuLabel:UILabel!
    
    private lazy var  effectView = {
        let blurEffect = UIBlurEffect(style: UIBlurEffect.Style.light)
        let view = UIVisualEffectView(effect: blurEffect)
        return view
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setZFMapViewControl()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate func setZFMapViewControl(){
        
        
        layerLabel =  UILabel()
        layerLabel.font = UIFont.iconfont(size: 22)
        layerLabel.text = .icon(icon: .ic_layer)
        layerLabel.snp.makeConstraints { make in
            make.width.height.equalTo(40)
        }
        layerLabel.isUserInteractionEnabled = true
        layerLabel.textAlignment = .center
        
    
        kefuLabel =  UILabel()
        kefuLabel.font = UIFont.iconfont(size: 22)
        kefuLabel.text = .icon(icon: .ic_kefu)
        kefuLabel.snp.makeConstraints { make in
            make.width.height.equalTo(40)
        }
        kefuLabel.isUserInteractionEnabled = true
        kefuLabel.textAlignment = .center
        
    
        let stackView =  UIStackView(arrangedSubviews: [layerLabel,kefuLabel])
        stackView.axis = .vertical
        stackView.alignment = .center
        stackView.spacing = 1
        stackView.distribution = .equalCentering
        addSubview(stackView)
        
        stackView.snp.makeConstraints { make in
            make.edges.equalToSuperview().inset(UIEdgeInsets.init(top: 5, left: 0, bottom: 5, right: 0))
            make.width.equalTo(40)
        }
        
        self.addRadius(radius: 5)

        backgroundColor = R.color.bg()

        
    }

}




class ZFMapLocationControlView: UIView {

    var locationLabel:UILabel!
    var pitchView:ZFPitchView!
    override init(frame: CGRect) {
        super.init(frame: frame)
        setZFMapLocationControlView()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate func setZFMapLocationControlView(){
        
        pitchView =  ZFPitchView()
        pitchView.snp.makeConstraints { make in
            make.width.height.equalTo(40)
        }

        locationLabel =  UILabel()
        locationLabel.font = UIFont.iconfont(size: 22)
        locationLabel.text = .icon(icon: .ic_location)
        locationLabel.snp.makeConstraints { make in
            make.width.height.equalTo(40)
        }
        locationLabel.isUserInteractionEnabled = true
        
        locationLabel.textAlignment = .center
        locationLabel.backgroundColor = R.color.bg()
        locationLabel.addRadius(radius: 5)
        locationLabel.isUserInteractionEnabled = true
        
        let stackView =  UIStackView(arrangedSubviews: [pitchView ,locationLabel])
        stackView.axis = .vertical
        stackView.alignment = .center
        stackView.spacing = 5
        stackView.distribution = .equalCentering
        addSubview(stackView)
        
        stackView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
            make.width.equalTo(40)
        }
        
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()

    }

}


class ZFPitchView :ZFBaseView {
    
    private var frontLabel : UILabel!
    private var backLabel : UILabel!
    @objc dynamic var isPitch:Bool = false
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setZFPitchView()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate func setZFPitchView(){
        
        backLabel =  UILabel()
        backLabel.font = UIFont.boldSystemFont(ofSize: 18)
        backLabel.text = "3D"
        backLabel.textAlignment = .center
        addSubview(backLabel)
        backLabel.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        
        backLabel.transform = CGAffineTransform(translationX: 0, y: -40)
        
        frontLabel =  UILabel()
        frontLabel.font = UIFont.boldSystemFont(ofSize: 18)
        frontLabel.text = "2D"
        frontLabel.textAlignment = .center
        addSubview(frontLabel)
        frontLabel.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
            
        backgroundColor = R.color.bg()
        addRadius(radius: 5)
 
        self.rx.observeWeakly(Bool.self, "isPitch").subscribe(onNext: {bo in
            UIView.feedback()
            UIView.animate(withDuration: 0.3) {
                if bo! {
                    self.backLabel.transform = CGAffineTransform.identity
                    self.frontLabel.transform = CGAffineTransform(translationX: 0, y: 40)
                }else {
                    self.backLabel.transform = CGAffineTransform(translationX: 0, y: -40)
                    self.frontLabel.transform = CGAffineTransform.identity
                }
            }
        }).disposed(by: dis)
        

        
    }
}
